package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.PetOperationPanelBtn;
import com.tool.btn.goodbtn;
import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;
import com.tool.tcp.NewPart;
import com.tool.tcpimg.UIUtils;
import org.come.entity.Goodstable;
import org.come.entity.RoleSummoning;
import org.come.mouslisten.ChoseAlchemyGoodsMouslisten;
import org.come.mouslisten.PetJlistChoseMouslisten2;
import org.come.mouslisten.WLLMouslisten;
import org.come.until.*;
import com.updateNew.MyIsif;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ZhshuanfutujianJpanel extends JPanel {
    private static final int warNum = -1;
    public static NewPart part;
    public static NewPart part1;
    public static NewPart part2;
    public static final int idx = -1;
    private static DefaultListModel<String> listModel;// 放置召唤兽的对象
    private final ChoseAlchemyGoodsMouslisten[] GoodsListListen = new ChoseAlchemyGoodsMouslisten[24];
    private JList<String> listpet;
    private Color fontcolor;
    private JScrollPane jScrollPane;
    private PetOperationPanelBtn btnalchemy;
    private JLabel jadeNum;
    private JLabel labRefined;
    private JLabel[] GoodsListLabel = new JLabel[24];
    private goodbtn[] btnrights;
    private int Flag = 0;
    private int count = 1;
    private ImageIcon icon;
    private ImageIcon icon1;
    private final BigDecimal money;
    private CardLayout cardLayout;

    public ZhshuanfutujianJpanel() {
        FormsOnOffBtn huanfu;
        JScrollPane jScrollPane1;
//        if ("水墨UI".equals(MyIsif.getStyle())) {
        this.setPreferredSize(new Dimension(520, 428));
        this.setLayout(null);
        this.setOpaque(false);
        this.add(getJadeNum()); //仙玉数量
        this.money = new BigDecimal(88888);//消耗仙玉数量
        // 关闭按钮事件
        if ("水墨UI".equals(MyIsif.getStyle())) {
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 607);
        offBtn.setBounds(488, 1, 25, 25);
        this.add(offBtn);
        } else {
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/ss815.png", 1, 607);
            offBtn.setBounds(499, 1, 25, 25);
            this.add(offBtn);
        }
        // 宠物列表对象
        listModel = new DefaultListModel<>();
        // 宠物列表
        listpet = new JList<>();
        listpet.setOpaque(false);
        listpet.setSelectionBackground(new Color(33, 42, 52));
        fontcolor = Color.GREEN;
        listpet.setSelectionForeground(fontcolor);
        listpet.setForeground(fontcolor);
        listpet.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        listpet.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
        listpet.setOpaque(false);
        listpet.setModel(listModel);
        DefaultListCellRenderer MyRenderer = new DefaultListCellRenderer() {
            final Color color = new Color(203, 181, 91);

            @Override
            public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (warNum == index) {
                    this.setForeground(color);
                } else {
                    this.setForeground(Color.white);
                }
                return this;
            }
        };
        listpet.setCellRenderer(new org.come.action.petpaixu.MyRenderer());
        listpet.addMouseListener(new PetJlistChoseMouslisten2(listpet, this));
//        listpet.addMouseMotionListener(new PetJlistChoseMouslisten2(listpet, this));
        // 召唤兽列表滚动条
        if ("水墨UI".equals(MyIsif.getStyle())) {
        jScrollPane = new JScrollPane(listpet);
        jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
        jScrollPane.getViewport().setOpaque(false);
        jScrollPane.setOpaque(false);
        jScrollPane.setBounds(46, 85, 150, 324);
        jScrollPane.setBorder(BorderFactory.createEmptyBorder());
        jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        this.add(jScrollPane);
            huanfu = new FormsOnOffBtn("inkImg/button/B409a.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.HYXLSJ17, "", 1000, this);
            huanfu.setBounds(202 + 110, 380, 79, 26);
            this.add(huanfu);
        } else {
            jScrollPane = new JScrollPane(listpet);
            jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            jScrollPane.getViewport().setOpaque(false);
            jScrollPane.setOpaque(false);
            jScrollPane.setBounds(46, 85, 150, 288);
            jScrollPane.setBorder(BorderFactory.createEmptyBorder());
            jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            this.add(jScrollPane);
            huanfu = new FormsOnOffBtn("inkImg/hongmu/ss663.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.HYXLSJ17, "", 1000, this);
            huanfu.setBounds(202 + 110, 380, 79, 26);
            this.add(huanfu);
        }


    }

    public JLabel getJadeNum() {
        if ("水墨UI".equals(MyIsif.getStyle())) {
        if (jadeNum == null) {
            jadeNum = new JLabel(RoleData.getRoleData().getLoginResult().getCodecard() + "");
            jadeNum.setBounds(425, 354, 80, 15);
            jadeNum.addMouseListener(new WLLMouslisten(36));
            jadeNum.setOpaque(false);
            jadeNum.setForeground(new Color(163, 229, 21));
            jadeNum.setFont(UIUtils.TEXT_NAME_FONT);//仙玉展示
        }
        } else {
            if (jadeNum == null) {
                jadeNum = new JLabel(RoleData.getRoleData().getLoginResult().getCodecard() + "");
                jadeNum.setBounds(424, 354, 80, 15);
                jadeNum.addMouseListener(new WLLMouslisten(36));
                jadeNum.setOpaque(false);
                jadeNum.setForeground(new Color(163, 229, 21));
                jadeNum.setFont(UIUtils.TEXT_NAME_FONT);//仙玉展示
            }
        }
        return jadeNum;
    }
public   static Map<String,String>good=new HashMap<>();
  static   HashMap<String, String> skinMap = new HashMap<>();
       static {
           skinMap.put("200185", "500175");//飞轩
           skinMap.put("200188", "500176");//莲生
           skinMap.put("200099", "500177");//幻·浪淘沙
           skinMap.put("200100", "500501");//幻·五叶
           skinMap.put("200097", "500179");//垂云叟
           skinMap.put("200101", "400525");//颜如玉
           skinMap.put("200098", "500181");//幻·范式之魂
           skinMap.put("200116", "500182");//幻·年兽
           skinMap.put("200184", "500183");//幻·灵听
           skinMap.put("200117", "400521");//幻·画中"仙
           skinMap.put("200140", "500643");//孟极
           skinMap.put("200123", "400518");//幻·白泽
           skinMap.put("200192", "9000128");//幻方
           skinMap.put("200124", "52370");//龙马
           skinMap.put("200191", "52370");//新手龙马
           skinMap.put("754", "592");//大娃
           skinMap.put("755", "593");//二娃
           skinMap.put("756", "594");//三娃
           skinMap.put("757", "595");//四娃
           skinMap.put("758", "596");//五娃
           skinMap.put("759", "597");//六娃
           skinMap.put("760", "598");//七娃
           skinMap.put("761", "599");//葫芦小金刚
           skinMap.put("200224", "500104");//白龙帝
           skinMap.put("200367", "900083");//天蓬元帅
           skinMap.put("200368", "900052");//孔雀仙子
           skinMap.put("200369", "8100225");//梅比斯耶
           skinMap.put("200370", "900082");//南海人鱼
           skinMap.put("200371", "hhjjl");//超级剑灵
           skinMap.put("200380", "500069");//乘黄
           skinMap.put("811", "52369");//龙小侠
           skinMap.put("812", "52370");//赤血龙马  //前面是pet的ID 后面是对应要改的新的SKIN皮肤

           good.put("200185", "17639");//飞轩
           good.put("200188", "17639");//莲生
           good.put("200099", "17639");//幻·浪淘沙
           good.put("200100", "17639");//幻·五叶
           good.put("200097", "17639");//垂云叟
           good.put("200101", "17639");//颜如玉
           good.put("200098", "17639");//幻·范式之魂
           good.put("200116", "17639");//幻·年兽
           good.put("200184", "17639");//幻·灵听
           good.put("200117", "17639");//幻·画中"仙
           good.put("200140", "17639");//孟极
           good.put("200123", "17639");//幻·白泽
           good.put("200192", "17639");//幻方
           good.put("200124", "17639");//龙马
           good.put("200191", "17639");//新手龙马
           good.put("754", "17639");//大娃
           good.put("755", "17639");//二娃
           good.put("756", "17639");//三娃
           good.put("757", "17639");//四娃
           good.put("758", "17639");//五娃
           good.put("759", "17639");//六娃
           good.put("760", "17639");//七娃
           good.put("761", "17639");//葫芦小金刚
           good.put("200224", "17639");//白龙帝
           good.put("200367", "17639");//天蓬元帅
           good.put("200368", "17639");//孔雀仙子
           good.put("200369", "17639");//梅比斯耶
           good.put("200370", "17639");//南海人鱼
           good.put("200371", "17639");//超级剑灵
           good.put("200380", "17639");//乘黄
           good.put("811", "17639");//龙小侠
           good.put("812", "17639");//赤血龙马
       }
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D graphics2d = (Graphics2D) g;
        if ("水墨UI".equals(MyIsif.getStyle())) {
        if (icon == null)
            icon = new ImageIcon("inkimg/Client/huanfu1.png");
        // 炼妖
        g.drawImage(icon.getImage(), 0, 0, 520, 428, this);
        Util.drawPrice(g, this.money, 280, 367);
        }else{
        if (icon1 == null)
            icon1 = new ImageIcon("inkimg/Client/huanfu.png");
        // 炼妖
        g.drawImage(icon1.getImage(), 0, 0, 520, 428, this);
        Util.drawPrice(g, this.money, 280, 367);
        }
        RoleSummoning pet = UserMessUntil.getChosePetMes();
// Use a HashMap to store the mapping between summoning ids and new skins

        pet.setSummoningNewskin(skinMap.getOrDefault(pet.getSummoningid(), pet.getSummoningid()));
        if (pet.getSid()!=null){

//            Goodstable ltrGoods = getGoodType(Long.parseLong(good.get(pet.getSummoningid()+"")));
//            int   num = ltrGoods == null ? 0 : ltrGoods.getUsetime();
//            if (num!=0){
//                g.drawString(num+"",375,328);//数量位置
//                g.drawImage(GoodsListFromServerUntil.imgpath(ltrGoods.getSkin()).getImage(),320,290,65,65,null);
//                setToolTipText("幻兽合成石,数量需要100个");//合成需要物品鼠标悬停显示
//            }
          //图片位置
        }//pet.getSid().toString()

        if (part1 == null) {
            part1 = pet.getPart();
        }
        if (part1 != null) {
            part1.draw(graphics2d, 255, 230, 0, ImageMixDeal.userimg.getTime());
        }
        if (part2 == null) {
            part2 = pet.getNewPart();
        }
        if (part2 != null) {
            part2.draw(graphics2d, 430, 230, 0, ImageMixDeal.userimg.getTime());
        }
        if (pet.getPetlock() == 1) {
            GoodsListFromServerUntil.drawPetLock(graphics2d, pet);
        }

        //消除文字锯齿
        //消除画图锯齿

//        } else {
//            if (this.icon == null) {
//                this.icon = new ImageIcon("sc/Client/huanfu.png");
//            }
//
//            g.drawImage(this.icon.getImage(), 0, 0, 509, 387, this);
//            Util.drawPrice(g, this.money, 230, 340);
//            RoleSummoning pet = UserMessUntil.getChosePetMes();
//// Use a HashMap to store the mapping between summoning ids and new skins
//            HashMap<String, String> skinMap = new HashMap<>();
//            skinMap.put("200046", "400066");
//            skinMap.put("200055", "400024");
//            skinMap.put("200057", "6019");
//            skinMap.put("200065", "6022");
//            skinMap.put("200073", "400073");
//            skinMap.put("200076", "6004");
//            skinMap.put("200077", "6006");
//            skinMap.put("200079", "6030");
//            skinMap.put("200085", "6008");
//            skinMap.put("200090", "6002");
//            skinMap.put("200093", "6014");
//            skinMap.put("200135", "6012");
//            skinMap.put("200147", "6010");
//            skinMap.put("200097", "400519");
//            skinMap.put("200098", "400520");
//            skinMap.put("200099", "400522");
//            skinMap.put("200100", "400524");
//            skinMap.put("200101", "400525");
//            skinMap.put("200116", "400523");
//            skinMap.put("200117", "400521");
//            skinMap.put("200123", "400518");
//            skinMap.put("200108", "6018");
//            skinMap.put("200140", "500167");
//            skinMap.put("200143", "400315");
//            skinMap.put("200158", "6023");
//            skinMap.put("200183", "500014");
//            skinMap.put("200187", "500171");
//            skinMap.put("200175", "6027");
//            skinMap.put("200177", "6029");
//            skinMap.put("200178", "6028");
//            skinMap.put("200191", "500183");
//            skinMap.put("200192", "500175");
//            skinMap.put("200193", "500176");
//            skinMap.put("200194", "5000134");
//            skinMap.put("200195", "500064");
//            skinMap.put("200196", "6024");
//            skinMap.put("200198", "728");
//            skinMap.put("200201", "6018");
//            skinMap.put("200202", "6626");
//            skinMap.put("200203", "6000");
//            skinMap.put("200204", "6019");
//            skinMap.put("200205", "6020");
//            skinMap.put("200206", "6032");
//            skinMap.put("200030", "6031");
//            pet.setSummoningNewskin(skinMap.getOrDefault(pet.getSummoningid(), pet.getSummoningid()));
//            if (part1 == null) {
//                part1 = pet.getPart();
//            }
//            if (part1 != null) {
//                part1.draw(graphics2d, 230, 200, 0, ImageMixDeal.userimg.getTime());
//            }
//            if (part2 == null) {
//                part2 = pet.getNewPart();
//            }
//            if (part2 != null) {
//                part2.draw(graphics2d, 420, 200, 0, ImageMixDeal.userimg.getTime());
//            }
//            if (pet.getPetlock() == 1) {
//                GoodsListFromServerUntil.drawPetLock(graphics2d, pet);
//            }
//            ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
//            Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
//            Configure configure = item.get(new BigDecimal(1));
//            if (listModel.size() <= 0) {
//                for (int i = 0; i < Integer.parseInt(configure.getNdslsx()); i++) {
//                }
//            }

        graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    /**
     * 鼠标进入
     *
     */
    public void mouseEntered(MouseEvent e) {
        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
    }
    /**
     * 鼠标离开
     *
     */
    public void mouseExited(MouseEvent e) {
        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
    }
    public JList<String> getListpet() {
        return this.listpet;
    }
    public void setListpet(JList<String> listpet) {
        this.listpet = listpet;
    }
    public DefaultListModel<String> getListModel() {
        return listModel;
    }
    public void setListModel(DefaultListModel<String> listModel) {
        ZhshuanfutujianJpanel.listModel = listModel;
    }
    public Color getFontcolor() {
        return this.fontcolor;
    }
    public void setFontcolor(Color fontcolor) {
        this.fontcolor = fontcolor;
    }
    public JScrollPane getjScrollPane() {
        return this.jScrollPane;
    }
    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }
    public PetOperationPanelBtn getBtnalchemy() {
        return this.btnalchemy;
    }
    public void setBtnalchemy(PetOperationPanelBtn btnalchemy) {
        this.btnalchemy = btnalchemy;
    }
    public JLabel getLabRefined() {
        return this.labRefined;
    }
    public void setLabRefined(JLabel labRefined) {
        this.labRefined = labRefined;
    }
    public JLabel[] getGoodsListLabel() {
        return this.GoodsListLabel;
    }
    public void setGoodsListLabel(JLabel[] goodsListLabel) {
        this.GoodsListLabel = goodsListLabel;
    }
    public int getFlag() {
        return this.Flag;
    }
    public void setFlag(int flag) {
        this.Flag = flag;
    }
    public int getCount() {
        return this.count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    public goodbtn[] getBtnrights() {
        return this.btnrights;
    }
    public void setBtnrights(goodbtn[] btnrights) {
        this.btnrights = btnrights;
    }
    public CardLayout getCardLayout() {
        return cardLayout;
    }

    // 初始列表
    public void initS(List<String> list) {
        listModel.clear();
        for (String s : list) {
            listModel.addElement(s);
        }
    }
    public static Goodstable getGoodType(long type) {
        Goodstable[] goodslist = GoodsListFromServerUntil.getGoodslist();
        Goodstable goodstable = null;
        int i = 0;

        for (int len = goodslist.length; i < len; ++i) {
            if (goodslist[i] != null && goodslist[i].getGoodsid().longValue() == type) {
                goodstable = goodslist[i];
                break;
            }
        }
        return goodstable;
    }
}
